﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DepartmentOnline.Models;

namespace DepartmentOnline
{
    public partial class Staff : System.Web.UI.Page
    {
        private Pagination Pager;

        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {
                Pager = new Pagination()
                            {
                                BindDataAction = bindData,
                                ViewState = this.ViewState
                            };
                bindData();
            }
            else
            {
                Pager = new Pagination()
                {
                    BindDataAction = bindData,
                    ViewState = this.ViewState
                };
                //since the pagination controls are dynamically creating its shld be re created in each page load
                Pager.BuildPagination(pnlPager);
            }
        }

        private void bindData()
        {
            using (var context = new departmentEntities())
            {
                DataTable data = context.Instructors.AsEnumerable().ToDataTable();
                Pager.BindDataWithPaging(Repeater1, data, pnlPager);
            }

        }

        public void RedirectToPerson(object sender, CommandEventArgs commandEventArgs)
        {
            Session["PersonID"] = commandEventArgs.CommandArgument;
            Response.Redirect("Person.aspx");
        }
    }
}